package com.jzoffer2;

import java.util.Scanner;

/**
 * TODO
 *
 * @author lefly
 * @version 1.0
 * @classname No04
 * @description
 * @date 2021/2/4 下午2:37
 */
public class No04 {
    public static void main(String[] args) {
        int[][] matrix = {
                {
                        1, 4, 7, 11, 15
                },
                {
                        2, 5, 8, 12, 19
                },
                {
                        3, 6, 9, 16, 22
                },
                {
                        10, 13, 14, 17, 24
                },
                {
                        18, 21, 23, 26, 30
                }
        };
        Scanner sc = new Scanner(System.in);
        int input = sc.nextInt();
        boolean res = findNumberIn2DArray(matrix,input);
        System.out.println(res);


    }

    public static boolean findNumberIn2DArray(int[][] matrix, int target) {
        if(matrix == null || matrix.length < 1 || matrix[0].length < 1){
            return false;
        }
        int rows = matrix.length,cols = matrix[0].length;
        int r = rows - 1,c = 0;
        while (r >= 0 && c < cols){
            if(matrix[r][c] == target){
                return true;
            }else if(matrix[r][c] > target){
                r--;
            }else {
                c++;
            }
        }
        return false;
    }

}
